home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / source / dialgmgr.sit / Dialogs ƒ / TextGroup.p < prev    next >
Text File  |  1989-11-29  |  3KB  |  132 lines

  1. unit TTextGroup;
  2.  
  3. {        ⌐1986-1989            Bill Stackhouse                                    }
  4. {                                Stackhouse Software                                }
  5. {                                Natick, MA 01760                                    }
  6.  
  7. interface
  8.  
  9. {$IFC UNDEFINED UseTextGroup}
  10. {$SETC UseTextGroup = FALSE}
  11. {$ENDC}
  12. {$IFC UseTextGroup}
  13.  
  14.     uses
  15.         TObject;
  16.  
  17.     const
  18.         maxTexts = 15;
  19.  
  20.     type
  21.         TTextGroup = object(TObject)
  22.                 numTextGroup: 0..maxTexts;                {number of radio/text groups}
  23.                 TextGroup: array[1..maxTexts] of record
  24.                         btnNum: Integer;                            {radio item number}
  25.                         textNum: Integer;                            {editText item number}
  26.                     end;
  27.                 procedure TTextGroup.Init;
  28.                 procedure TTextGroup.Add (pBtn: Integer;    {pairs of btn and edit text items}
  29.                                             pText: Integer);
  30.                 procedure TTextGroup.Click (curDialog: dialogPtr;
  31.                                             theItem: Integer);
  32.                 function TTextGroup.Error: Integer;
  33.             end;
  34.  
  35. {$ENDC}
  36.  
  37. implementation
  38.  
  39. {$IFC UseTextGroup}
  40.  
  41.     const
  42.         Off = 0;
  43.         On = 1;
  44.  
  45.         btnCtrlItem = 4;
  46.         chkCtrlItem = 5;
  47.         radCtrlItem = 6;
  48.         editCtrlItem = 16;
  49.  
  50.         DialogGroupIgnored = -10;    {too many groups, key, menus, or user items were added}
  51.  
  52.     type
  53.         TSearch = (searching, found, endList);
  54.  
  55.     var
  56.         globalError: Integer;
  57.  
  58.     procedure TextClickEdit (curDialog: DialogPtr;
  59.                                     theItem: Integer);
  60.         var
  61.             theType: Integer;
  62.             theHandle: handle;
  63.             theBox: Rect;
  64.     begin
  65.         GetDItem(curDialog, theItem, theType, theHandle, theBox);
  66.         if theType = editCtrlItem then
  67.             SelIText(curDialog, theItem, 0, 241);
  68.     end;        {TextClickEdit}
  69.  
  70.     procedure TTextGroup.Init;
  71.     begin
  72.         globalError := noErr;
  73.         SELF.numTextGroup := 0;
  74.     end;        {TTextGroup.Init}
  75.  
  76.     procedure TTextGroup.Add (pBtn: Integer;    {pairs of btn and edit text items}
  77.                                     pText: Integer);
  78.     begin
  79.         globalError := noErr;
  80.         with SELF do
  81.             if numTextGroup < maxTexts then
  82.                 begin
  83.                     numTextGroup := numTextGroup + 1;
  84.                     with TextGroup[numTextGroup] do
  85.                         begin
  86.                             btnNum := pBtn;
  87.                             textNum := pText;
  88.                         end;
  89.                 end
  90.             else
  91.                 globalError := DialogGroupIgnored;
  92.     end;        {TTextGroup.Add}
  93.  
  94.     procedure TTextGroup.Click (curDialog: dialogPtr;
  95.                                     theItem: Integer);
  96.         var
  97.             theType: Integer;
  98.             theHandle: handle;
  99.             theBox: Rect;
  100.             index: Integer;
  101.             state: TSearch;
  102.             oldValue: Integer;
  103.     begin
  104.         globalError := noErr;
  105.         GetDItem(curDialog, theItem, theType, theHandle, theBox);
  106.         if theType = chkCtrlItem then
  107.             begin
  108.                 oldValue := GetCtlValue(ControlHandle(theHandle));
  109.                 SetCtlValue(ControlHandle(theHandle), BitXor(oldValue, On));
  110.                 state := searching;
  111.                 index := 1;
  112.                 repeat
  113.                     if (SELF.TextGroup[index].btnNum = theItem) then
  114.                         state := found
  115.                     else if index > SELF.numTextGroup then
  116.                         state := endList
  117.                     else
  118.                         index := index + 1;
  119.                 until (state <> searching);
  120.                 if (state = found) and (oldValue = Off) then
  121.                     TextClickEdit(curDialog, SELF.TextGroup[index].textNum);
  122.             end;
  123.     end;        {TTextGroup.Key}
  124.  
  125.     function TTextGroup.Error: Integer;
  126.     begin
  127.         Error := globalError;
  128.     end;        {TTextGroup.Error}
  129.  
  130. {$ENDC}
  131.  
  132. end.